package com.soda.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.soda.bean.Course;
import com.soda.bean.Student;
import com.soda.service.CourseServiceHan;
import com.soda.service.impl.CourseServiceHanImpl;
import com.soda.util.PageInfo;



public class HeaderSousuoServletHan extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String met =request.getParameter("met");
		HttpSession session = request.getSession();
		
		CourseServiceHan csh = new CourseServiceHanImpl();
		PageInfo pi = new PageInfo(1, 4, 0, 0);
		if("0".equals(met)){
			int coutype=1;
			String fenye="fen";
			
			String couname =request.getParameter("couname");
			//分页
			int condiTotal = csh.couTypeCount(couname,coutype);
			pi.setTotal(condiTotal);
			String num=request.getParameter("page");
			if (num!= null) {
				pi.setPage(Integer.parseInt(num));
			}

			List<Course> list =csh.getcouTypeSelect(couname,coutype,pi.getPage(),pi.getPer());
			
			session.setAttribute("mohuname", couname);
			request.setAttribute("sousuo", list);
			request.setAttribute("page", pi);
			request.getRequestDispatcher("qiantai/xianchang.jsp").forward(request, response);	
			return;
		}
		if("1".equals(met)){
			int coutype=0;
			String couname =request.getParameter("couname");
			
			//分页
			int condiTotal = csh.couTypeCount(couname,coutype);
			pi.setTotal(condiTotal);
			String num=request.getParameter("page");
			if (num!= null) {
				pi.setPage(Integer.parseInt(num));
			}

			List<Course> list = csh.getcouTypeSelect(couname, coutype,pi.getPage(),pi.getPer());
			
			request.setAttribute("sousuo`", list);
			session.setAttribute("mohuname", couname);
			request.setAttribute("page", pi);
			request.getRequestDispatcher("qiantai/video.jsp").forward(request, response);
			
		}if("2".equals(met)){
			int a=2;
			int b=4;
			Student stu = (Student)session.getAttribute("student");
			int id=stu.getStuId();
			//System.out.println(id);
			String couname= request.getParameter("couname");
			//分页
			int condiTotal = csh.couIdCount(id,couname,a,b);
			pi.setTotal(condiTotal);
			String num=request.getParameter("page");
			if (num!= null) {
				pi.setPage(Integer.parseInt(num));
			}
			List<Course> list = csh.getByIdSelectCourse(id,couname,pi.getPage(),pi.getPer());
			request.setAttribute("course1", list);
			session.setAttribute("couname", couname);
			request.setAttribute("page", pi);
			request.getRequestDispatcher("qiantai/course.jsp").forward(request, response);
			
		}
		if("3".equals(met)){
			int a=1;
			int b=3;
			String fenye = "han";
			Student stu = (Student)session.getAttribute("student");
			int id=stu.getStuId();
			String couname= request.getParameter("couname");
			if(couname==null){
				response.sendRedirect("HeaderSousuoServletHan?met=wodekecheng");
			}
			//分页
			int condiTotal = csh.couIdCount(id,couname,a,b);
			pi.setTotal(condiTotal);
			String num=request.getParameter("page");
			if (num!= null) {
				pi.setPage(Integer.parseInt(num));
			}
			List<Course> list = csh.getSelectCourseWeijie(id,couname,pi.getPage(),pi.getPer());
			session.setAttribute("sousuocouname", couname);
			request.setAttribute("page", pi);
			request.setAttribute("fenye", fenye);
			request.setAttribute("course", list);
			request.getRequestDispatcher("qiantai/pay.jsp").forward(request, response);
			
		}
			
		if("wodekecheng".equals(met)){
		int a=2;
		int b=4;
			
		Student stu = (Student)session.getAttribute("student");
		int id=stu.getStuId();
		//分页
		int condiTotal = csh.couIdCountShouYe(id,a,b);
		pi.setTotal(condiTotal);
		String num=request.getParameter("page");
		if (num!= null) {
			pi.setPage(Integer.parseInt(num));
		}
		
		List<Course> list = csh.getByIdSelectCourse(id,pi.getPage(),pi.getPer());
		request.setAttribute("page", pi);
		request.setAttribute("shouye", list);
		request.getRequestDispatcher("qiantai/course.jsp").forward(request, response);
			
			
		}
		if("weijiesuan".equals(met)){
			int a=1;
			int b=3;
			String fenye="han";
			Student stu = (Student)session.getAttribute("student");
			int id=stu.getStuId();
			//分页
			int condiTotal = csh.couIdCountShouYe(id,a,b);
			pi.setTotal(condiTotal);
			String num=request.getParameter("page");
			if (num!= null) {
				pi.setPage(Integer.parseInt(num));
			}
			List<Course> list = csh.getByIdSelectCourseWeijie(id,pi.getPage(),pi.getPer());
			request.setAttribute("han", fenye);
			request.setAttribute("page", pi);
			request.setAttribute("course", list);
			request.getRequestDispatcher("qiantai/pay.jsp").forward(request, response);
		}
			


		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
